//
//  ClusterListSource.m
//  HiQ
//
//  Created by arvintan on 12-8-5.
//
//

#import "MacrosDefine.h"
#import "ImageAndTextCell.h"
#import "ClusterListSource.h"
#import "MainWindowController.h"
#import "Buddy.h"




@implementation ClusterListSource

@synthesize clusterGroupArray;

// Data source method

- (id)init
{
    clusterGroupArray = [[NSMutableArray alloc] init];
    
    ClusterGroup *discussion = [[ClusterGroup alloc] init];
    discussion->groupName = NSLocalizedString(@"讨论组", nil);
    discussion->groupId = 0;
//    ClusterGroup *group = [[ClusterGroup alloc] init];
//    group->groupName = @"群";
//    group->groupId = 1;
//    [clusterGroupArray addObject:group];
    
    [clusterGroupArray addObject:discussion];
    
    return [super init];
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
    if(item == nil)
        item = clusterGroupArray;
    
    if(item == clusterGroupArray)
        return [item objectAtIndex:index];
    
    if([item isKindOfClass:[ClusterGroup class]])
        return ((Buddy*)[((ClusterGroup*)item)->clusterList objectAtIndex:index]);
    
    return nil;
}

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
    if(item == nil)
        return NO;
    
    if([item isKindOfClass:[ClusterGroup class]])
        return YES;
    
    return NO;
}

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
    if(item == nil)
        item = clusterGroupArray;
    
    if(item == clusterGroupArray)
        return [item count];
    
    if([item isKindOfClass:[ClusterGroup class]])
        return [((ClusterGroup*)item)->clusterList count];
    
    return 0;
}

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
    if ([[tableColumn identifier] isEqualToString: @"ClusterList"])
	{
        if(item == nil)
            return nil;
        
        if([item isKindOfClass:[ClusterGroup class]])
            return ((ClusterGroup *)item)->groupName;
        
        //    if([item isKindOfClass:[Buddy class]])
        //        return ((Buddy*)item)->buddyName;
    }
    return nil;
}


@end



